﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WHC.Hotel.UI.Controls
{   


    public partial class RoomStatusView : UserControl
    {

        public delegate void RoomStatusViewDoubleClickHandler(Panel sender, EventArgs e);
        public delegate void RoomStatusViewMouseClickHandler(Panel sender, MouseEventArgs e);
        public delegate void RoomStatusViewMouseHoverHandler(Panel sender, EventArgs e);
        public delegate void RoomStatusViewMouseLeaveHandler(Panel sender, EventArgs e);
        public event  RoomStatusViewDoubleClickHandler  RoomStatusViewDoubleClickEvent;
        public event RoomStatusViewMouseClickHandler RoomStatusViewMouseClickEvent;
        public event RoomStatusViewMouseHoverHandler RoomStatusViewMouseHoverEvent;
        public event RoomStatusViewMouseLeaveHandler RoomStatusViewMouseLeaveEvent;
        public RoomStatusView()
        {
            InitializeComponent();
            //RoomNum.Parent = picStatus;
            this.BindEvent();
            //this.BackColor = this.roomPanel.BackColor;


        }

        private void BindEvent()
        {

            //双击事件
            this.roomPanel.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);
            this.RoomNum.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);
            this.picStatus.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);
            this.picAlert.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);
            this.picArrive.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);
            this.pivleft.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);
            this.RoomTypeCode.DoubleClick += new EventHandler(RoomStatusView_DoubleClick);



            //鼠标单击事件
            this.roomPanel.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);
            this.RoomNum.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);
            this.picStatus.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);
            this.picAlert.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);
            this.picArrive.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);
            this.pivleft.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);
            this.RoomTypeCode.MouseDown += new MouseEventHandler(RoomStatusView_MouseClick);


            //鼠标划入事件
            this.RoomNum.MouseEnter += new EventHandler(RoomStatusView_MouseHover);
            
           
            //鼠标划出事件

            this.RoomNum.MouseLeave += new EventHandler(RoomStatusView_MouseLeave);
           
        
        
        
        }

        void RoomStatusView_MouseLeave(object sender, EventArgs e)
        {

            if (RoomStatusViewMouseLeaveEvent != null)
            {
                RoomStatusViewMouseLeaveEvent(GetSelectControlPanel(sender), e);
            }
        }

  
        void RoomStatusView_MouseHover(object sender, EventArgs e)
        {
            if (RoomStatusViewMouseHoverEvent != null)
            {
                RoomStatusViewMouseHoverEvent(GetSelectControlPanel(sender), e);
            }
        }

        void RoomStatusView_MouseClick(object sender, MouseEventArgs e)
        {
            if (RoomStatusViewMouseClickEvent != null)
            {

                RoomStatusViewMouseClickEvent(GetSelectControlPanel(sender), e);
            }
               
        }


        void RoomStatusView_DoubleClick(object sender, EventArgs e)
        {
            if (RoomStatusViewDoubleClickEvent != null)
            {
                RoomStatusViewDoubleClickEvent(GetSelectControlPanel(sender), e);
            }
        }


        private Panel GetSelectControlPanel(object sender)
        {
        
                Panel selectedPanel=null;
                if (sender.GetType().Name == "Panel")
                {

                     selectedPanel=  (Panel)sender;
                }
                else
                {
                    selectedPanel = (Panel)((Control)sender).Parent;
                
                }
                return selectedPanel;

        
        
        }
      
    }
}
